package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
/**
 * Servlet implementation class request
 */

public class request extends HttpServlet 
{

	Connection conn=null;;
	PreparedStatement pstmt=null;
	RequestDispatcher rd;
	int updateStatement=0;
	PrintWriter out;
	
	public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
	{	
		out=response.getWriter();
		String name,phone1,phone2,addr,addr2,state,city,flat,budget,loc;	
		name=request.getParameter("Name");
		phone1=request.getParameter("phone1");
		phone2=request.getParameter("phone2");
		addr=request.getParameter("Address");
		flat=request.getParameter("Flat");
		budget=request.getParameter("Budget");
		loc=request.getParameter("Location");
		addr2=request.getParameter("Address2");
		state=request.getParameter("state");
		city=request.getParameter("city");
		
		//response.setContentType("text/html)");
		String query;
		out.println(name);
		out.println(phone1);
		out.println(phone2);
		out.println(addr);
		out.println(flat);
		out.println(budget);
		out.println(loc);
		out.println(addr2);
		out.println(state);
		out.println(city);
	
		
		
		try
		{
			//out.println("1");
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			//out.println("2");
			conn=DriverManager.getConnection("Jdbc:Odbc:siteDSN","scott","tiger");
			//out.println("3");
			query="insert into customer values(?,?,?,?,?,?,?,?,?,?)";
			//out.println(query);
			pstmt=conn.prepareStatement(query);
			pstmt.setString(1,name);
			pstmt.setString(2,phone1);
			pstmt.setString(3, phone2);
			pstmt.setString(4,addr);
			pstmt.setString(5,flat);
			pstmt.setString(6,budget);
			pstmt.setString(7,loc);
			pstmt.setString(8,state);
			pstmt.setString(9,city);
			pstmt.setString(10,addr2);
			
			//out.println("4");
			updateStatement=pstmt.executeUpdate();
			//out.println("5");
			
			if (updateStatement!=0)
				{
				out.println("Data Inserted Succesfully");
				response.sendRedirect("Contact Us.jsp");
				}
			else
				out.println("Sorry");
					
			/*rd=request.getRequestDispatcher("Contact Us.jsp");
			rd.include(request,response);
			response.sendRedirect("Success.jsp");*/
			
			/*out.println("<form name=Result method=get action=Result.jsp>");
			out.println("<input type=submit value=Show Data>");
			out.println("</form>");
			out.println("</body>");
			out.println("</html>");*/
		}
		
		catch(Exception sqlexception)
		{
			sqlexception.printStackTrace();
		}
		/*finally
		{
			pstmt.close();
			conn.close();
			
			
			<table border=2>
	  			<tr>
	  				<td><img src="<%=request.getContextPath()%>/Gallary/Palm.gif " alt="palm garden"></img>
	  				</td>
	  				<td><img src="/PropertySite/Gallary/Palm logo.png"  alt="palm garden"></img></td>
	  			</tr>
	  		</table>
	  		
	  		//From Result later to be pasted
	  		
	  		<form action="export_to_excel.jsp">
		<table width=98% >
		<tr><td>
		<input type=submit value="Export to Excel"></input>
		</td></tr>
		</table>
		</form>
	  		
	  		
	  		
	  		
		}
		*/
	}
}	
		
		
	

